#ifndef DOSING_PUMP_H
#define DOSING_PUMP_H

#include <avr/pgmspace.h>
#include "WProgram.h"

#include <LiquidCrystal.h>
#include <EEPROM.h>

#include "utility.h";
#include "Clock.h";
#include "Alerts.h";

const byte DOSING_PUMP_NUMBER_OF_PROGRAMS     = 3;  
const byte DOSING_PUMP_SET_NUMBER_OF_LINE = DOSING_PUMP_NUMBER_OF_PROGRAMS*4;
const byte DOSING_PUMP_GEN_NUMBER_OF_LINE = 6;

const int DOSING_PUMP_CALIBRATION_AMOUNT = 40;

class Dosing_Pump
{
public:
  Dosing_Pump() {
  };

  void init(byte _PumpNum,int _Pump_Pin_Num,int _Stirrer_Pin_Num);
  void Save_To_EEPROM();

  void Check_Pump_programs();
  void update(bool new_min,bool new_sec);

  bool Key_Prass_Gen(byte index,char Key);
  bool Print_promt_Gen();
  void Print_Gen(byte index);
  void Key_Prass_Set(byte index,char Key);
  void Print_Set(byte index);

  void Print_Liquid(byte _Pump_Liquid_Amount_l ,   byte _Pump_Liquid_Amount_h);
  void Print_History();
  void Clear_History();
  void Print_Last_Time();

  void Start(byte _Stirrer_Time , byte _Pump_Liquid_Amount_l ,   byte _Pump_Liquid_Amount_h);

  int   History;
  byte History_l;  
  byte Pump_Liquid_Amount_l_last_time;
  byte Pump_Liquid_Amount_h_last_time;

  void Start_Pump_Calibration();
  void End_Pump_Calibration();

private:
  void Turn_Stirrer_On();     // Tuen the Stirrer on
  void Turn_Stirrer_Off();     // Tuen the Stirrer off
  void Turn_Pump_On();  // Tuen the Pump on
  void Turn_Pump_Off();  // Tuen the Pump off

  void Check_Alert();
  bool Check_Program_day(byte Cur_Day,byte program_num);
  void Cheange_Program_day(byte Day,byte program_num);

  float Get_Liquid_Amount(byte _Pump_Liquid_Amount_l ,   byte _Pump_Liquid_Amount_h);
  float Get_Liquid_Amount(byte program_num);
  void Print_Liquid(byte program_num);

  int   Pump_Pin_Num;
  int   Stirrer_Pin_Num;
  byte PumpNum;

  unsigned long Last_time_update;
  int Stirrer_Run_Time;
  byte Stirrer_Start_Time;
  unsigned long  Pump_Run_Time;


  byte Day; // use for gui x(day) index
  bool Pump_Calibration_ask;
  bool Pump_Calibration_in;
  unsigned long Calibration_Start_Time;


  bool Pump_mode;
  byte Stirrer_Time; // in min
  byte Stirrer_Speed; 
  unsigned long Pump_ml2time;
  byte   Alert; // 1-> 10 ml

  bool Clear_history_ask;

  bool Program_Mode[DOSING_PUMP_NUMBER_OF_PROGRAMS];
  byte Program_Days[DOSING_PUMP_NUMBER_OF_PROGRAMS];
  byte Start_Pump_HR[DOSING_PUMP_NUMBER_OF_PROGRAMS];
  byte Start_Pump_MIN[DOSING_PUMP_NUMBER_OF_PROGRAMS];

  byte Pump_Liquid_Amount_l[DOSING_PUMP_NUMBER_OF_PROGRAMS];
  byte Pump_Liquid_Amount_h[DOSING_PUMP_NUMBER_OF_PROGRAMS];

  bool MoreThenMax;
  bool TimeNotRun;
};


#endif



















